package gui;

import gui.cen.Center;
import gui.cen.home.HomeScreen;
import java.awt.*;
import javax.swing.*;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class Segl2 extends JPanel {
    public static int HOME = 0;
    public static int TABLE = 1;
    public static int TREE = 2;
    public static int READ = 3;
    public static int POSTERIORS = 4;

    private HomeScreen hs;
    private Segl1 segL1;
    private CardLayout layout;

    public Segl2(Segl1 segL1){
        super(new BorderLayout());
        this.setBorder(BorderFactory.createEmptyBorder(3,2,3,2));
        this.segL1 = segL1;
        layout = new CardLayout();
        this.setLayout(layout);
        this.add(new HomeScreen(), "Welcome");
        layout.show(this, "Welcome");
    }

    public void updateAllCardsOnFrameResize(){
        try{center.updateTable();}catch(Exception e){}
        try{center.updateReads();}catch(Exception e){}
        try{center.updateTree();}catch(Exception e){}
        try{center.updatePlots();}catch(Exception e){}
    }

    private Center center;
    public void loadCard(int which, boolean reset){
        if(hs!=null){hs.stopTicker();}
        if(which==HOME){
            this.add(new HomeScreen(), "Welcome");
            layout.show(this, "Welcome");
        }
        else{
            if(center == null || reset){this.add(center = new Center(this, which), "Palign");}
            else{center.loadCard(which);}
            layout.show(this, "Palign");
            if(which==TABLE){center.updateTable();}
            else if(which==READ){center.updateReads();}
            else if(which==TREE){center.updateTree();}
        }
    }

    public Segl1 getSegl1(){return segL1;}
    public Center getCenter(){return center;}
    public void refreshContainer(){segL1.refreshContainer();}
    public void resetCenterGUI(){center = null;}
    public void updatePlots(){if(center!=null){center.updatePlots();}}
    public void msg(String msg){segL1.msg(msg);}
    public void inDetProg(int which){segL1.idPrg(which);}
    public void detProg(int which, int val){segL1.dPrg(which, val);}
}